
#include "Riemann2DProblem.h"
// #include "boost/assign.hpp"
// #include "boost/typeof/typeof.hpp"
#include <functional>
// using namespace boost::assign;

template<>
InputParameters validParams<Riemann2DProblem>()
{
  InputParameters params = validParams<EulerProblem>();
  MooseEnum sub_types(" case1  case2  case3  case4  case5  case6  case7  case8  case9  case10 case11 case12 case13 case14 case15 case16 case17 case18 case19");
  params.addRequiredParam<MooseEnum>("sub_type", sub_types, "2D Riemann 问题");
  return params;
}

Riemann2DProblem::Riemann2DProblem(const InputParameters &params) :
	EulerProblem(params),
	_sub_type(getParam<MooseEnum>("sub_type"))
{
	vector<Real> initial_condition[4];
	if(_sub_type == "case1")
	{
		initial_condition[0].assign({1,0,0,0,1}) ;
		initial_condition[1].assign({ 0.5197,-0.7259,0,0,0.4});
		initial_condition[2].assign({0.1072,-0.7259,-1.4045,0,0.0439}) ;
		initial_condition[3].assign({0.2578,0,-1.4045,0,0.15}) ;
	}
	if(_sub_type == "case2")
	{
		initial_condition[0].assign({1,0,0,0,1}) ;
		initial_condition[1].assign({0.5197,-0.7259,0,0,0.4}) ;
		initial_condition[2].assign({1,-0.7259,-0.7259,0,1}) ;
		initial_condition[3].assign({0.5197,0,-0.7259,0,0.4}) ;
	}
	if(_sub_type == "case3")
	{
		initial_condition[0].assign({1.5,0,0,0,1.5}) ;
		initial_condition[1].assign({0.5323,1.206,0,0,0.3}) ;
		initial_condition[2].assign({0.138,1.206,1.206,0,0.029}) ;
		initial_condition[3].assign({0.5323,0,1.206,0,0.3}) ;
	}
	if(_sub_type == "case4")
	{
		initial_condition[0].assign({1.1,0,0,0,1.1}) ;
		initial_condition[1].assign({0.5065,0.8939,0,0,0.35}) ;
		initial_condition[2].assign({1.1,0.8939,0.8939,0,1.1}) ;
		initial_condition[3].assign({0.5065,0,0.8939,0,0.35}) ;
	}
	if(_sub_type == "case5")
	{
		initial_condition[0].assign({1,-0.75,-0.5,0,1}) ;
		initial_condition[1].assign({2,-0.75,0.5,0,1}) ;
		initial_condition[2].assign({1,0.75,0.5,0,1}) ;
		initial_condition[3].assign({3,0.75,-0.5,0,1}) ;
	}
	if(_sub_type == "case6")
	{
		initial_condition[0].assign({1,0.75,-0.5,0,1}) ;
		initial_condition[1].assign({2,0.75,0.5,0,1}) ;
		initial_condition[2].assign({1,-0.75,0.5,0,1}) ;
		initial_condition[3].assign({3,-0.75,-0.5,0,1}) ;
	}
	if(_sub_type == "case7")
	{
		initial_condition[0].assign({1,0.1,0.1,0,1}) ;
		initial_condition[1].assign({0.5197,-0.6259,0.1,0,0.4}) ;
		initial_condition[2].assign({0.8,0.1,0.1,0,0.4}) ;
		initial_condition[3].assign({0.5197,0.1,-0.6259,0,0.4}) ;
	}

	if(_sub_type == "case8")
	{
		initial_condition[0].assign({0.5197,0.1,0.1,0,0.4}) ;
		initial_condition[1].assign({1,-0.6259,0.1,0,1}) ;
		initial_condition[2].assign({0.8,0.1,0.1,0,1}) ;
		initial_condition[3].assign({1,0.1,-0.6259,0,1}) ;
	}
	if(_sub_type == "case9")
	{
		initial_condition[0].assign({1,0,0.3,0,1}) ;
		initial_condition[1].assign({2,0,-0.3,0,1}) ;
		initial_condition[2].assign({1.039,0,-0.8133,0,0.4}) ;
		initial_condition[3].assign({0.5197,0,-0.4259,0,0.4}) ;
	}
	if(_sub_type == "case10")
	{
		initial_condition[0].assign({1,0,0.4297,0,1}) ;
		initial_condition[1].assign({0.5,0,0.6076,0,1}) ;
		initial_condition[2].assign({0.2281,0,-0.6076,0,0.3333}) ;
		initial_condition[3].assign({0.4562,0,-0.4297,0,0.3333}) ;
	}
	if(_sub_type == "case11")
	{
		initial_condition[0].assign({1,0.1,0,0,1}) ;
		initial_condition[1].assign({0.5313,0.8276,0,0,0.4}) ;
		initial_condition[2].assign({0.8,0.1,0,0,0.4}) ;
		initial_condition[3].assign({ 0.5313,0.1,0.7276,0,0.4});
	}
	if(_sub_type == "case12")
	{
		initial_condition[0].assign({0.5313,0,0,0,0.4}) ;
		initial_condition[1].assign({1,0.7276,0,0,1}) ;
		initial_condition[2].assign({0.8,0,0,0,1}) ;
		initial_condition[3].assign({1,0,0.7276,0,1}) ;
	}
	if(_sub_type == "case13")
	{
		initial_condition[0].assign({1,0,-0.3,0,1}) ;
		initial_condition[1].assign({2,0,0.3,0,1}) ;
		initial_condition[2].assign({1.0625,0,0.8145,0,0.4}) ;
		initial_condition[3].assign({0.5313,0,0.4276,0,0.4}) ;
	}
	if(_sub_type == "case14")
	{
		initial_condition[0].assign({2,0,-0.5605,0,8}) ;
		initial_condition[1].assign({1,0,-1.2172,0,8}) ;
		initial_condition[2].assign({0.4736,0,1.2172,0,2.6667}) ;
		initial_condition[3].assign({0.9474,0,1.1606,0,2.6667}) ;
	}
	if(_sub_type == "case15")
	{
		initial_condition[0].assign({1,0.1,-0.3,0,1}) ;
		initial_condition[1].assign({0.5197,-0.6259,-0.3,0,0.4}) ;
		initial_condition[2].assign({0.8,0.1,-0.3,0,0.4}) ;
		initial_condition[3].assign({0.5313,0.1,0.4276,0,0.4}) ;
	}
	if(_sub_type == "case16")
	{
		initial_condition[0].assign({0.5313,0.1,0.1,0,0.4}) ;
		initial_condition[1].assign({1.0222,-0.6179,0.1,0,1}) ;
		initial_condition[2].assign({0.8,0.1,0.1,0,1}) ;
		initial_condition[3].assign({1,0.1,0.8276,0,1}) ;
	}
	if(_sub_type == "case17")
	{
		initial_condition[0].assign({1,0,-0.4,0,1}) ;
		initial_condition[1].assign({2,0,-0.3,0,1}) ;
		initial_condition[2].assign({1.0625,0,0.2145,0,0.4}) ;
		initial_condition[3].assign({0.5197,0,-1.1259,0,0.4}) ;
	}
	if(_sub_type == "case18")
	{
		initial_condition[0].assign({1,0,1,0,1}) ;
		initial_condition[1].assign({2,0,-0.3,0,1}) ;
		initial_condition[2].assign({1.0625,0,0.2145,0,0.4}) ;
		initial_condition[3].assign({0.5197,0,0.2741,0,0.4}) ;
	}
	if(_sub_type == "case19")
	{
		initial_condition[0].assign({1,0,0.3,0,1}) ;
		initial_condition[1].assign({2,0,-0.3,0,1}) ;
		initial_condition[2].assign({1.0625,0,0.2145,0,0.4}) ;
		initial_condition[3].assign({0.5197,0,-0.4259,0,0.4}) ;

	}

	_initial[BoundingBox(Point(0.5,0.5), Point(1,1))].swap(initial_condition[0]);
	_initial[BoundingBox(Point(0,0.5), Point(0.5,1))].swap(initial_condition[1]);
	_initial[BoundingBox(Point(0,0), Point(0.5,0.5))].swap(initial_condition[2]);
	_initial[BoundingBox(Point(0.5,0), Point(1,0.5))].swap(initial_condition[3]);
}

void Riemann2DProblem::initialCondition(Real* value, Real t, const Point& p)
{
	for(auto it = _initial.begin(); it != _initial.end(); ++it)
	{
		if(it->first.contains_point(p))
		{
			primaryTOConservation(&(it->second[0]), value);
			return ;
		}
	}
}

void Riemann2DProblem::boundaryCondition(Real *value, Real t, const Point &p)
{
	mooseError("Riemann2DProblem::boundaryCondition采用紧致边界");
}
